# CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 项目名称
project(pcbDetect)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


# 查找 nlohmann_json 库
find_package(nlohmann_json 3.2.0 REQUIRED)

#查找 OpenCV 库
find_package(OpenCV REQUIRED )

# 添加链接 pthread 库
find_package(Threads REQUIRED)

# 添加 ONNX Runtime 库
set(ONNXRUNTIME_DIR ./lib/onnxruntime-linux-aarch64-1.16.0)
include_directories(${ONNXRUNTIME_DIR}/include)
link_directories(${ONNXRUNTIME_DIR}/lib)


# MQTT 配置
set(PAHO_MQTTCPP_INCLUDE_DIRS "/usr/local/include")
set(PAHO_MQTTCPP_LIBRARIES "/usr/local/lib/libpaho-mqttpp3.so")
set(PAHO_MQTTC_LIBRARIES
    "/usr/local/lib/libpaho-mqtt3a.so"
    "/usr/local/lib/libpaho-mqtt3as.so"
    "/usr/local/lib/libpaho-mqtt3as.so.1"
    "/usr/local/lib/libpaho-mqtt3c.so"
    "/usr/local/lib/libpaho-mqtt3cs.so"
)

#JSON 配置

# 收集所有源文件（递归查找所有 .cpp 文件）
file(GLOB_RECURSE SOURCES 
    "${PROJECT_SOURCE_DIR}/app/*.cpp"
    "${PROJECT_SOURCE_DIR}/camera/*.cpp"
    "${PROJECT_SOURCE_DIR}/mqttClient/*.cpp"
    "${PROJECT_SOURCE_DIR}/uart/*.cpp"
    "${PROJECT_SOURCE_DIR}/protocol/*.cpp"
    "${PROJECT_SOURCE_DIR}/detectAlg/*.cpp"
    # 可根据需要添加更多目录
)

# 添加头文件目录
include_directories(
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_SOURCE_DIR}/app
    ${PROJECT_SOURCE_DIR}/camera
    ${PROJECT_SOURCE_DIR}/mqttClient
    ${PROJECT_SOURCE_DIR}/uart
    ${PROJECT_SOURCE_DIR}/protocol
    ${PROJECT_SOURCE_DIR}/detectAlg
    ${PAHO_MQTTCPP_INCLUDE_DIRS}
)

# 创建可执行程序
add_executable(${PROJECT_NAME} ${SOURCES})

# 链接依赖库
target_link_libraries(${PROJECT_NAME} 
    # V4L2 相关库
    v4l2
    v4lconvert
    
    # MQTT 客户端库
    ${PAHO_MQTTCPP_LIBRARIES}
    ${PAHO_MQTTC_LIBRARIES}
    
    # 串口通信库（如果使用）
    # pthread
    
    # JSON 处理库
    nlohmann_json::nlohmann_json

    # OpenCV 处理库
    ${OpenCV_LIBS}

    # onnxruntime 处理库
    onnxruntime

    #Threads处理库
    Threads::Threads
)

# 设置编译选项
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2")